package com.seocoo.worker.base.multiImage;

import com.seocoo.worker.base.http.BaseRsp;
import com.sfh.lib.HandleException;
import com.sfh.lib.IResult;
import com.sfh.lib.mvvm.BaseViewModel;

import java.io.File;

public class UpLoadImageModel extends BaseViewModel {

    /***
     * 上传图片
     * @param path
     */
    public void upLoadFile(String path) {
        showLoading(false);
        this.execute(new ReqUploadFiles(new File(path)), new IResult<BaseRsp<RspImage>>() {
            @Override
            public void onFail(HandleException e) {
                hideLoading();
                setValue("onUpLoadError");
            }

            @Override
            public void onSuccess(BaseRsp<RspImage> eFileBaseRsp) throws Exception {
                hideLoading();
                if (eFileBaseRsp.success()) {
                    RspImage data = eFileBaseRsp.getData();
                    setValue("onUpLoadSuccess", data);
                } else {
                    setValue("onUpLoadError");
                }
            }
        });

    }

}
